import { HTML_NODE_TYPE } from "../../constant";
import { genNode } from "./process";

class CodegenState {

    constructor (complieOptions) {
        // 编译配置保存
        this.options = complieOptions;

        // 静态节点渲染函数数组
        this.staticRenderFns = [];
        // data 特殊属性生成函数（例如： class， style）
        this.dataGenFns = complieOptions.dataGenFns;

        // 可能需要该属性
        this.componentInstance = complieOptions.instance;

        // 语法状态标记
        this.inPre = false;
        this.inOnce = false;
        this.inFor = false;

    }
}

export function generate (astNode, complieOptions) {
    // 生成 编译器设置
    const state = new CodegenState(complieOptions);
    // 检查特殊标签
    const code = astNode ?
        (
            astNode === "script"
                ? 'null'
                : genNode(astNode, state)
        )
        :'_c("div")';
    // 返回渲染函数
    return {
        renderFn: `with(this){ return ${code}; }`,
        staticRenderFns: state.staticRenderFns
    };
}







